<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备名称" prop="name">
        <el-input
            v-model="queryParams.name"
            placeholder="请输入设备名称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="number">
        <el-input
            v-model="queryParams.number"
            placeholder="请输入设备编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="设备状态" prop="status">-->
<!--        <el-select v-model="queryParams.status" placeholder="请选择设备状态" clearable>-->
<!--          <el-option-->
<!--              v-for="dict in this.dicts.device_status"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="Search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="deviceList">
      <el-table-column label="操作" align="center" width="55" class-name="small-padding">
        <template #default="scope">
          <el-button
              size="mini"
              type="text"
              @click="handleClickRow(scope.row)"
          >定位
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="设备名称" align="center" prop="name">
      </el-table-column>
      <el-table-column label="设备编号" align="center" prop="number"/>
      <el-table-column label="设备状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="dicts.device_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        class="pagination-container"
        :layout="'prev, pager, next'"
        :autoScroll="false"
        v-show="total > 0"
        :total="total"
        :small="true"
        :background="false"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

  </div>

</template>

<script>
import {listDevice} from "@/api/device";
import {getCurrentInstance} from "vue";

export default {
  name: "DeviceListMap",

  data() {
    return {
      //字典
      dicts: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备管理表格数据
      deviceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        name: null,
        number: null,
        type: null,
        equipment: null,
        project: null,
        status: null,
        pic: null,
        address: null,
        coordinateLon: null,
        coordinateLat: null,
        workTimes: null,
        durationH: null,
        durationM: null,
        beginTime: null,
        endTime: null,
        lastOnline: null,
      },

    };
  },
  created() {
    this.getList();
    const {proxy} = getCurrentInstance();

    this.dicts = proxy.useDict("device_status");
  },
  mounted() {

  },
  methods: {
    handler() {

    },
    handleInitd() {
    },
    handleClickRow(row) {

      let number = row.number;
      //向父组件传值
      this.$emit('position-event', number)
    },

    /** 查询设备管理列表 */
    getList() {
      this.loading = true;
      listDevice(this.queryParams).then(response => {
        this.deviceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


  }
};
</script>
<style scoped>
.pagination-container {
  right: 0;
  position: relative;
}
</style>
